<?php

class DownloadController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
        /**
         * nel caso voglio proteggere i download
         */
        /*
        if (userHasNoPermissions) {
                $this->view->msg = 'This file cannot be downloaded!';
                $this->_forward('error', 'download');
                return FALSE;
            }
        */

         $file = APPLICATION_PATH.'/../images/bsoggi-whichclub.pdf';
         if (file_exists($file)) {

            // disable the view ... and perhaps the layout
            $this->view->layout()->disableLayout();
            $this->_helper->viewRenderer->setNoRender(true);

            header('Content-Type: application/x-pdf');
            header('Content-Disposition: attachment; filename="'.basename($file).'"');

            readfile($file);


        }

    }

    public function errorAction()
    {
        // action body
    }

    public function imageAction()
    {
        // action body
         $file = APPLICATION_PATH.'/../images/whichclub_640x280.png';
         if (file_exists($file)) {

            // disable the view ... and perhaps the layout
            $this->view->layout()->disableLayout();
            $this->_helper->viewRenderer->setNoRender(true);

            //header('Content-Description: File Transfer');
            //header('Content-Type: application/octet-stream');

            header('Content-Type: "image/png"');
            header('Content-Disposition: attachment; filename="'.basename($file).'"');
            
            //header('Content-Transfer-Encoding: binary');
            //header('Expires: 0');
            //header('Cache-Control: must-revalidate');
            //header('Pragma: public');
            //header('Content-Length: ' . filesize($file));
            ob_clean();
            flush();
            readfile($file);
           

        }
		print_r($file);
    }

	public function image2Action()
    {
        // action body
         $file = APPLICATION_PATH.'/../images/whichclub_346x346.png';
         if (file_exists($file)) {

            // disable the view ... and perhaps the layout
            $this->view->layout()->disableLayout();
            $this->_helper->viewRenderer->setNoRender(true);

            //header('Content-Description: File Transfer');
            //header('Content-Type: application/octet-stream');

            header('Content-Type: "image/png"');
            header('Content-Disposition: attachment; filename="'.basename($file).'"');
            
            //header('Content-Transfer-Encoding: binary');
            //header('Expires: 0');
            //header('Cache-Control: must-revalidate');
            //header('Pragma: public');
            //header('Content-Length: ' . filesize($file));
            ob_clean();
            flush();
            readfile($file);
           

        }

    }

	public function image3Action()
    {
        // action body
         $file = APPLICATION_PATH.'/../images/whichclub_bolle_1000x1000.png';
         if (file_exists($file)) {

            // disable the view ... and perhaps the layout
            $this->view->layout()->disableLayout();
            $this->_helper->viewRenderer->setNoRender(true);

            //header('Content-Description: File Transfer');
            //header('Content-Type: application/octet-stream');

            header('Content-Type: "image/png"');
            header('Content-Disposition: attachment; filename="'.basename($file).'"');
            
            //header('Content-Transfer-Encoding: binary');
            //header('Expires: 0');
            //header('Cache-Control: must-revalidate');
            //header('Pragma: public');
            //header('Content-Length: ' . filesize($file));
            ob_clean();
            flush();
            readfile($file);
           

        }

    }


}





